/**
 ******************************************************************************
 * @file    it.c
 * @author  MCD Application Team
 * @brief   Main Interrupt Service Routines.
 *          This file provides template for all exceptions handler and
 *          peripherals interrupt service routine.
 ******************************************************************************
 */

/* Includes ------------------------------------------------------------------*/
#include "bsp.h"
#include "bsp_cpu_it.h"
#include "os_obj.h"

/******************************************************************************
 *                              function
 ******************************************************************************/
void USART1_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void USART2_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void USART3_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void UART4_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void UART5_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void UART6_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void UART7_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void UART8_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));

/******************************************************************************
 *                                var
 ******************************************************************************/
cpu_it_type cpu_it;

/**
 * @brief  This function handles USART0_IRQHandler exception.
 * @param  None
 * @retval None
 */
void USART1_IRQHandler(void)
{
    GET_INT_SP();
    /* enter interrupt */
    rt_interrupt_enter();

    if (cpu_it.uart01)
        cpu_it.uart01();

    /* leave interrupt */
    rt_interrupt_leave();
    FREE_INT_SP();
}

/**
 * @brief  This function handles USART0_IRQHandler exception.
 * @param  None
 * @retval None
 */
void USART2_IRQHandler(void)
{
    GET_INT_SP();
    /* enter interrupt */
    rt_interrupt_enter();

    if (cpu_it.uart02)
        cpu_it.uart02();

    /* leave interrupt */
    rt_interrupt_leave();
    FREE_INT_SP();
}

/**
 * @brief  This function handles USART3_IRQHandler exception.
 * @param  None
 * @retval None
 */
void USART3_IRQHandler(void)
{
    GET_INT_SP();
    /* enter interrupt */
    rt_interrupt_enter();

    if (cpu_it.uart03)
        cpu_it.uart03();

    /* leave interrupt */
    rt_interrupt_leave();
    FREE_INT_SP();
}

/**
 * @brief  This function handles USART4_IRQHandler exception.
 * @param  None
 * @retval None
 */
void UART4_IRQHandler(void)
{
    GET_INT_SP();
    /* enter interrupt */
    rt_interrupt_enter();

    if (cpu_it.uart04)
        cpu_it.uart04();

    /* leave interrupt */
    rt_interrupt_leave();
    FREE_INT_SP();
}

/**
 * @brief  This function handles USART5_IRQHandler exception.
 * @param  None
 * @retval None
 */
void UART5_IRQHandler(void)
{
    GET_INT_SP();
    /* enter interrupt */
    rt_interrupt_enter();

    if (cpu_it.uart05)
        cpu_it.uart05();

    /* leave interrupt */
    rt_interrupt_leave();
    FREE_INT_SP();
}

/**
 * @brief  This function handles USART6_IRQHandler exception.
 * @param  None
 * @retval None
 */
void UART6_IRQHandler(void)
{
    GET_INT_SP();
    /* enter interrupt */
    rt_interrupt_enter();

    if (cpu_it.uart06)
        cpu_it.uart06();

    /* leave interrupt */
    rt_interrupt_leave();
    FREE_INT_SP();
}

/**
 * @brief  This function handles UART7_IRQHandler exception.
 * @param  None
 * @retval None
 */
void UART7_IRQHandler(void)
{
    GET_INT_SP();
    /* enter interrupt */
    rt_interrupt_enter();

    if (cpu_it.uart07)
        cpu_it.uart07();

    /* leave interrupt */
    rt_interrupt_leave();
    FREE_INT_SP();
}

/**
 * @brief  This function handles USART8_IRQHandler exception.
 * @param  None
 * @retval None
 */
void UART8_IRQHandler(void)
{
    GET_INT_SP();
    /* enter interrupt */
    rt_interrupt_enter();

    if (cpu_it.uart08)
        cpu_it.uart08();

    /* leave interrupt */
    rt_interrupt_leave();
    FREE_INT_SP();
}
